//单位转换

// 瞬时流量
export const convertVelocityFlow = (v, unit = "m³/h", criticality = 10000) => {
    if (localStorage.getItem('unitOption')) {
        let unitOption = JSON.parse(localStorage.getItem('unitOption'))
        criticality = unitOption.ssllcriticality
    }
    // m³/h 立方米每小时
    let m = v / 1;
    return m + ' m³/h'
    // if (unit === "m³/h") {
    //     if (m >= criticality) {
    //         return L + " L/h";
    //     }
    //     return m + ` ${unit}`;
    // }
    // if (unit === "L/h") {
    //     return L + " L/h";
    // }
};
// 累计流量
export const convertTotalFlow = (v, unit, criticality = 10000) => {
    if (localStorage.getItem('unitOption')) {
        let unitOption = JSON.parse(localStorage.getItem('unitOption'))
        criticality = unitOption.ljllcriticality
    }
    let m = v / 1;
    let k = m / 1000;
    if (m >= criticality) {
        return k.toFixed(2) + " km³";
    }
    return m.toFixed(2) + " m³";
};

// 瞬时热量
export const convertThermalPower = (
    v,
    unit = 'kw',
    heatunit = "W",
    criticality = 10000
) => {
    let kw = v / 1;
    let mw = kw / 1000;
    let MJ_h = v * 3.6;
    let GJ_h = MJ_h / 1000;
    if (localStorage.getItem('unitOption')) {
        let unitOption = JSON.parse(localStorage.getItem('unitOption'))
        heatunit = unitOption.heatunit
        criticality = unitOption.ssrlcriticality
    }
    if (heatunit === "W") {
        if (kw >= criticality) {
            return mw.toFixed(2) + " MW"
        }
        return kw.toFixed(2) + " KW";
    }
    if ((heatunit = "J")) {
        if (MJ_h >= criticality) {
            return GJ_h.toFixed(2) + " GJ/h";
        }
        return MJ_h.toFixed(2) + " MJ/h";
    }
    //     if (type == "w") {
    //     if (v >= 10000) {
    //       return v / 1000 + " mw";
    //     }
    //     return v + " kw";
    //   }
    //   if (type == "J/h") {
    //     let MJ = v * 3.6;
    //     if (MJ >= 10000) {
    //       return MJ / 1000 + " GJ/h";
    //     }
    //     return MJ + " MJ/h";
    //   }
};
// 累计热量
export const convertCurrentHeatOrCold = (
    v,
    unit,
    heatunit = "W",
    criticality = 10000
) => {
    let KWh = v / 1;
    let MWh = v / 1000;
    let GWh = MWh / 1000;
    let MJ = KWh * 3.6;
    let GJ = MJ / 1000;
    let TJ = GJ / 1000;
    if (localStorage.getItem('unitOption')) {
        let unitOption = JSON.parse(localStorage.getItem('unitOption'))
        heatunit = unitOption.heatunit
        criticality = unitOption.ljrlcriticality
    }
    if (heatunit == "W") {
        if (KWh >= criticality && MWh < criticality) {
            return MWh.toFixed(2) + " MWh";
        }
        if (MWh >= criticality) {
            return GWh.toFixed(2) + " GWh";
        }
        return KWh.toFixed(2) + " KWh";
    }
    if (heatunit === "J") {
        if (MJ >= criticality && GJ < criticality) {
            return GJ.toFixed(2) + " GJ";
        }
        if (GJ >= criticality) {
            return TJ.toFixed(2) + " TJ";
        }
        return MJ.toFixed(2) + " MJ";
    }
    //   if (type === "wh") {
    //     if (v >= 10000000) {
    //       return v / 1000 / 1000 + " GWh";
    //     }
    //     if (v >= 10000) {
    //       return v / 1000 + " MWh";
    //     }
    //     return v + " KWh";
    //   }
    //   if (type === "j") {
    //     let MJ = (v * 3600) / 1000;
    //     if (MJ > 10000000) {
    //       return MJ / 1000 / 1000 + " TJ";
    //     }
    //     if (v >= 10000) {
    //       return MJ / 1000 + " GJ";
    //     }
    //     return MJ + "MJ";
    //   }
};
